package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;


import com.kaisengit.enity.Guide;

import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class GuideDao {
	
	private DBHelp <Guide> db = new DBHelp<Guide>();

	public void save(Guide guide) {
		
		String sql = "insert into t_guide (id,guidename,tel) values (?,?,?)";
		db.executeSQL(sql, guide.getId(),guide.getGuidename(),guide.getTel());
	}

	

	public Guide findByname(String name) {
		String sql = "select id ,guidename,tel from t_guide where guidename = ?";
		
		return db.executeQueryForObject(sql, new GuideRowMapper(), name);
		
	}
	
	private class GuideRowMapper implements RowMapper<Guide>{
		
		public Guide mapperRow (ResultSet rs) throws SQLException{
			
			Guide guide = new Guide();
			guide.setId(rs.getString("id"));
			guide.setGuidename(rs.getString("guidename"));
			guide.setTel(rs.getString("tel"));
			
			return guide;
			
			
		}
	}

}
